<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 劳寄修
  Date: 2021/3/2
  Time: 16:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>上报维修</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/toastr.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/tips.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/mFrame/newtool.js"></script>
</head>
<body>
<%--格式化时间--%>
<%
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String tDate = sdf.format(new Date());

%>
<div class="container shadow-sm p-3 mb-5 bg-white rounded">
    <div class="row">
        <div class="col-12">
            <div id="reform" >
                <nav class="navbar  navbar-light rounded" style="background-color: #1e5379;margin-bottom: 30px;">
                    <a class="navbar-brand" href="#" style="color: white;">维修设备</a>
                </nav>
            </div>
        </div>

    </div>
    <div class="row">
        <div class="col-3"></div>
        <div class="col-6">
            <form id="form">
                <div class="form-group row">
                    <label for="eName" class="row-lg-2 col-form-label">设备名称：</label>
                    <div class="col-lg-10">
                        <input type="text" name="eName" class="form-control" id="eName" >
                    </div>
                </div>


                <div class="form-group row">
                    <label for="etype" class="row-lg-2 col-form-label">设备类型：</label>
                    <div class="col-lg-10">
                        <select class="form-control form-control-lg" name="etype" id="etype">
                            <%--etype--%>
                            <c:forEach var="row"  items="${etype}">
                                <option value="${row.id}">${row.type}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>



                <div class="form-group row">
                    <label for="model" class="row-lg-2 col-form-label">设备型号：</label>
                    <div class="col-lg-10">
                        <input type="text" name="model" class="form-control" id="model">
                    </div>
                </div>

                <div class="form-group row">
                    <label for="receiver" class="row-lg-2 col-form-label">维修人：&nbsp;&nbsp;&nbsp;&nbsp;</label>
                    <div class="col-lg-10">
                        <input type="text" name="receiver" class="form-control" id="receiver" >
                    </div>
                </div>

                <div class="form-group row">
                    <label for="giveTime" class="row-lg-2 col-form-label">送修时间：</label>
                    <div class="col-lg-10">
                        <input type="date" name="giveTime" class="form-control" value="<%=tDate%>" id="giveTime">
                    </div>
                </div>

                <div class="form-group row">
                    <label for="mailPlace" class="row-lg-2 col-form-label">寄出地点：</label>
                    <div class="col-lg-10">
                        <input type="text" name="mailPlace" class="form-control" id="mailPlace" >
                    </div>
                </div>

                <div class="form-group row">
                    <label for="damage" class="row-lg-2 col-form-label">损坏原因：</label>
                    <div class="col-lg-10">
                        <input type="text" name="damage" class="form-control" id="damage">
                    </div>
                </div>

                <div class="form-group row">
                    <button type="button" onclick="sendData()" class="btn btn-success" id="addR">维修设备</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button type="button" class="btn btn-primary" id="resetData">重置</button>
                </div>

            </form>

        </div>
        <div class="col-3"></div>
    </div>
</div>
</body>

    <script type="text/javascript">
        customTips();
        var eId=0;
        var prefixPath="${pageContext.request.contextPath}";
        var notNull = new RegExp(".*[^\s]","i");
        var notNumber=new RegExp("[1][0-9]{0,10}");
        var $trs1=$(".form-group");
        $(function () {
            $('.dropdown-toggle').dropdown();




            //重置
            $("#refreshData").click(function (){
                window.parent.frames.detailed("/pj/addRep");
            });

            //判断该设备是否存在
            $("#eName").on("blur",function () {
                var ll=$("#eName").val();
                var typeID=$("#etype").val();

                if (notNull.test(ll)){
                    console.log(typeID)
                    queryEp($trs1[0],"eName","该设备不存在","en",JSON.stringify({"eName":ll}));
                }else {
                    StartCheck($trs1[0],"eName","不可为空","en",false);
                }
            });

            //判断类型
            $("#etype").on("change",function () {
                var ll=$("#eName").val();
                var typeID=$("#etype").val();
                console.log(ll+"\t"+typeID)
                queryEp($trs1[1],"myType","该设备没有这个类型","qq",JSON.stringify({"eName":ll,"typeId":typeID}));

            });


            $("#model").on("blur",function () {//判断型号
                var ll=$("#eName").val();
                var typeID=$("#etype").val();
                var model=$("#model").val();
                if (notNull.test(model)){
                    queryEp($trs1[2],"model","该设备没有这个型号","cc",JSON.stringify({"eName":ll,"typeId":typeID,"eModel":model}));
                }else {
                    StartCheck($trs1[2],"model","不可为空","cc",false);
                }
            });



            $("#receiver").on("blur",function () {
                var model=$("#receiver").val();
                if (notNull.test(model)){
                    StartCheck($trs1[3],"receiver","","bb",true);
                }else {
                    StartCheck($trs1[3],"receiver","不可为空","bb",false);
                }
            });


            $("#mailPlace").on("blur",function () {
                var ll=$("#mailPlace").val();
                if (notNull.test(ll)){
                    StartCheck($trs1[5],"mailPlace","","haha",true);
                }else {
                    StartCheck($trs1[5],"mailPlace","不可为空","haha",false);
                }
            });


            $("#damage").on("blur",function () {
                var ll=$("#damage").val();
                if (notNull.test(ll)){
                    StartCheck($trs1[6],"damage","","cks",true);
                }else {
                    StartCheck($trs1[6],"damage","不可为空","cks",false);
                }
            });


        });


        function queryEp(tIdl,inpId,error,newInpID,val){//查询设备
             $.ajax({
                 type:"post",
                 contentType:"aplication/json;charset=utf-8",
                 dataType:"json",
                 url:prefixPath+"/rep/queryEp2",
                 data:val,
                 success:function (data){
                         StartCheck(tIdl,inpId,error,newInpID,data.state);
                 },
                 error:function (e){

                     console.log(e)
                     alert("服务器异常");

                 }


             })


        }





        function  sendData() {
                var tid=$("#etype").val();
                var receiver= $("#receiver").val();
                var giveTime= $("#giveTime").val();
                var mailPlace= $("#mailPlace").val();
                var damage= $("#damage").val();

                var msg={"tid":tid,"receiver":receiver,"giveTime":giveTime,"mailPlace":mailPlace,"damage":damage};

                if (
                    tid.trim()!=""&&
                    receiver.trim()!=""&&
                    giveTime.trim()!=""&&
                    mailPlace.trim()!=""&&
                    damage.trim()!=""
                ){
                        $.ajax({
                            type:"post",
                            dataType: "json",
                            contentType: "application/json;charset=utf-8",
                            url:prefixPath+"/rep/addRep",
                            data:JSON.stringify(msg),
                            success:function (data) {
                                if (data.state){
                                    toastr.success("上报成功");
                                    window.parent.frames.detailed("/pj/addRep");
                                }else{
                                    toastr.error("请检查数据");
                                }
                            },
                            error:function (e) {
                                console.log(e);
                                toastr.error("服务器异常");
                            }
                        });

                    }else {

                    toastr.warning("请填入数据");
                }


        }





    </script>


</html>
